From f5653e2502792657ee67120bedb69d6d3387a3da Mon Sep 17 00:00:00 2001 From: Sven Neumann Date: Sat, 29 Mar 2008 19:02:20 +0000 Subject: [PATCH] babl/babl-component.c babl/babl-conversion.c babl/babl-db.c 2008-03-29 Sven Neumann * babl/babl-component.c * babl/babl-conversion.c * babl/babl-db.c * babl/babl-extension.c * babl/babl-fish-path.c * babl/babl-fish-reference.c * babl/babl-fish-simple.c * babl/babl-format.c * babl/babl-model.c * babl/babl-type.c: applied patch from Jan Heller that changes the code to test for a pre-existent instance of a babl class in the database before creating a new one. svn path=/trunk/; revision=298 --- ChangeLog | 15 +++++++++ babl/babl-component.c | 20 ++++++++---- babl/babl-conversion.c | 34 +++++++++++++-------- babl/babl-db.c | 6 ---- babl/babl-extension.c | 5 +-- babl/babl-fish-path.c | 20 ++++++++---- babl/babl-fish-reference.c | 21 +++++++++---- babl/babl-fish-simple.c | 20 ++++++++---- babl/babl-format.c | 62 +++++++++++++++++++++++--------------- babl/babl-model.c | 24 ++++++++++----- babl/babl-type.c | 20 ++++++++---- 11 files changed, 164 insertions(+), 83 deletions(-) diff --git a/ChangeLog b/ChangeLog index ec56ead..5193253 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2008-03-29 Sven Neumann + + * babl/babl-component.c + * babl/babl-conversion.c + * babl/babl-db.c + * babl/babl-extension.c + * babl/babl-fish-path.c + * babl/babl-fish-reference.c + * babl/babl-fish-simple.c + * babl/babl-format.c + * babl/babl-model.c + * babl/babl-type.c: applied patch from Jan Heller that changes the + code to test for a pre-existent instance of a babl class in the + database before creating a new one. + 2008-03-24 Tor Lillqvist * babl/babl-type.c: Make the "test" array static. diff --git a/babl/babl-component.c b/babl/babl-component.c index 84562cc..ef28dc6 100644 --- a/babl/babl-component.c +++ b/babl/babl-component.c @@ -109,14 +109,22 @@ babl_component_new (void *first_arg, va_end (varg); + babl = babl_db_exist (db, id, first_arg); + if (babl) + { + /* There is an instance already registered by the required id/name, + * returning the preexistent one instead. + */ + return babl; + } + babl = component_new (first_arg, id, luma, chroma, alpha); - { - Babl *ret = babl_db_insert (db, babl); - if (ret != babl) - babl_free (babl); - return ret; - } + /* Since there is not an already registered instance by the required + * id/name, inserting newly created class into database. + */ + babl_db_insert (db, babl); + return babl; } BABL_CLASS_TEMPLATE (component) diff --git a/babl/babl-conversion.c b/babl/babl-conversion.c index 27eb77e..ab122bb 100644 --- a/babl/babl-conversion.c +++ b/babl/babl-conversion.c @@ -79,7 +79,7 @@ conversion_new (const char *name, } else if (planar) { - babl_fatal ("planar conversions not supported for %ssupported", + babl_fatal ("planar conversions not supported for %s", babl_class_name (source->class_type)); } break; @@ -257,18 +257,26 @@ babl_conversion_new (void *first_arg, { type = BABL_CONVERSION_PLANAR; } - babl = conversion_new (create_name (source, destination, type), - id, source, destination, linear, plane, planar); - - { - Babl *ret = babl_db_insert (db, babl); - if (ret != babl) - babl_free (babl); - else - babl_add_ptr_to_list ((void ***) ((Babl *) &(source->type.from)), babl); - - return ret; - } + + char * name = create_name (source, destination, type); + + babl = babl_db_exist (db, id, name); + if (babl) + { + /* There is an instance already registered by the required id/name, + * returning the preexistent one instead. + */ + return babl; + } + + babl = conversion_new (name, id, source, destination, linear, plane, planar); + + /* Since there is not an already registered instance by the required + * id/name, inserting newly created class into database. + */ + babl_db_insert (db, babl); + babl_add_ptr_to_list ((void ***) ((Babl *) &(source->type.from)), babl); + return babl; } static long diff --git a/babl/babl-db.c b/babl/babl-db.c index 735bdbc..2cd95a7 100644 --- a/babl/babl-db.c +++ b/babl/babl-db.c @@ -94,12 +94,6 @@ Babl * babl_db_insert (BablDb *db, Babl *item) { - - Babl *found = babl_db_exist (db, item->instance.id, item->instance.name); - - if (found) - return found; - if (item->instance.id) babl_hash_table_insert (db->id_hash, item); babl_hash_table_insert (db->name_hash, item); diff --git a/babl/babl-extension.c b/babl/babl-extension.c index ebadb5f..9219fad 100644 --- a/babl/babl-extension.c +++ b/babl/babl-extension.c @@ -184,7 +184,7 @@ babl_extension_load (const char *path) init = dlsym (dl_handle, "init"); if (!init) { - babl_log ("\n\tint babl_extension_init() function not found in extenstion '%s'", path); + babl_log ("\n\tint babl_extension_init() function not found in extension '%s'", path); dlclose (dl_handle); return load_failed (babl); } @@ -202,7 +202,8 @@ babl_extension_load (const char *path) return load_failed (babl); } - if (babl_db_insert (db, babl) == babl) + babl_db_insert (db, babl); + if (babl == babl_db_exist_by_name (db, path)) { babl_set_extender (NULL); return babl; diff --git a/babl/babl-fish-path.c b/babl/babl-fish-path.c index afbb1df..ada4116 100644 --- a/babl/babl-fish-path.c +++ b/babl/babl-fish-path.c @@ -284,6 +284,15 @@ babl_fish_path (const Babl *source, char *name = create_name (source, destination, 1); BablConversion *temp_chain[BABL_HARD_MAX_PATH_LENGTH]; + babl = babl_db_exist_by_name (babl_fish_db (), name); + if (babl) + { + /* There is an instance already registered by the required name, + * returning the preexistent one instead. + */ + return babl; + } + babl_assert (BABL_IS_BABL (source)); babl_assert (BABL_IS_BABL (destination)); @@ -329,12 +338,11 @@ babl_fish_path (const Babl *source, return NULL; } - { - Babl *ret = babl_db_insert (babl_fish_db (), babl); - if (ret != babl) - babl_free (babl); - return ret; - } + /* Since there is not an already registered instance by the required + * name, inserting newly created class into database. + */ + babl_db_insert (babl_fish_db (), babl); + return babl; } static long diff --git a/babl/babl-fish-reference.c b/babl/babl-fish-reference.c index 073f7db..beb5364 100644 --- a/babl/babl-fish-reference.c +++ b/babl/babl-fish-reference.c @@ -51,6 +51,15 @@ babl_fish_reference (const Babl *source, Babl *babl = NULL; char *name = create_name (source, destination, 1); + babl = babl_db_exist_by_name (babl_fish_db (), name); + if (babl) + { + /* There is an instance already registered by the required name, + * returning the preexistent one instead. + */ + return babl; + } + babl_assert (BABL_IS_BABL (source)); babl_assert (BABL_IS_BABL (destination)); @@ -71,12 +80,12 @@ babl_fish_reference (const Babl *source, babl->fish.error = 0.0; /* assuming the provided reference conversions for types and models are as exact as possible */ - { - Babl *ret = babl_db_insert (babl_fish_db (), babl); - if (ret != babl) - babl_free (babl); - return ret; - } + + /* Since there is not an already registered instance by the required + * name, inserting newly created class into database. + */ + babl_db_insert (babl_fish_db (), babl); + return babl; } diff --git a/babl/babl-fish-simple.c b/babl/babl-fish-simple.c index 0d096a2..6c933d8 100644 --- a/babl/babl-fish-simple.c +++ b/babl/babl-fish-simple.c @@ -34,6 +34,15 @@ babl_fish_simple (BablConversion *conversion) name = create_name (conversion); + babl = babl_db_exist_by_name (babl_fish_db (), name); + if (babl) + { + /* There is an instance already registered by the required name, + * returning the preexistent one instead. + */ + return babl; + } + babl = babl_malloc (sizeof (BablFishSimple) + strlen (name) + 1); babl->class_type = BABL_FISH_SIMPLE; @@ -50,10 +59,9 @@ babl_fish_simple (BablConversion *conversion) reference, and babl fish reference only requests clean conversions */ - { - Babl *ret = babl_db_insert (babl_fish_db (), babl); - if (ret != babl) - babl_free (babl); - return ret; - } + /* Since there is not an already registered instance by the required + * name, inserting newly created class into database. + */ + babl_db_insert (babl_fish_db (), babl); + return babl; } diff --git a/babl/babl-format.c b/babl/babl-format.c index ab4fc60..0a16669 100644 --- a/babl/babl-format.c +++ b/babl/babl-format.c @@ -45,24 +45,25 @@ format_new (const char *name, { Babl *babl; - { - int i; - /* i is desintation position */ - for (i = 0; i < model->components; i++) - { - int j; - - for (j = 0; j < components; j++) - { - if (component[j] == model->component[i]) - goto component_found; - } - babl_fatal ("matching source component for %s in model %s not found", - model->component[i]->instance.name, model->instance.name); -component_found: - ; - } - } + /* i is desintation position */ + int i, j, component_found = 0; + for (i = 0; i < model->components; i++) + { + for (j = 0; j < components; j++) + { + if (component[j] == model->component[i]) + { + component_found = 1; + break; + } + } + if (!component_found) + { + component_found = 0; + babl_fatal ("matching source component for %s in model %s not found", + model->component[i]->instance.name, model->instance.name); + } + } /* allocate all memory in one chunk */ babl = babl_malloc (sizeof (BablFormat) + @@ -295,17 +296,28 @@ babl_format_new (void *first_arg, va_end (varg); - babl = format_new (name ? name : create_name (model, components, component, type), + if (!name) + name = create_name (model, components, component, type); + + babl = babl_db_exist (db, id, name); + if (babl) + { + /* There is an instance already registered by the required id/name, + * returning the preexistent one instead. + */ + return babl; + } + + babl = format_new (name, id, planar, components, model, component, sampling, type); - { - Babl *ret = babl_db_insert (db, babl); - if (ret != babl) - babl_free (babl); - return ret; - } + /* Since there is not an already registered instance by the required + * id/name, inserting newly created class into database. + */ + babl_db_insert (db, babl); + return babl; } int diff --git a/babl/babl-model.c b/babl/babl-model.c index 99ef35e..6a212b5 100644 --- a/babl/babl-model.c +++ b/babl/babl-model.c @@ -161,14 +161,24 @@ babl_model_new (void *first_argument, va_end (varg); - babl = model_new (create_name (name, components, component), id, components, component); + name = create_name (name, components, component); - { - Babl *ret = babl_db_insert (db, babl); - if (ret != babl) - babl_free (babl); - return ret; - } + babl = babl_db_exist (db, id, name); + if (babl) + { + /* There is an instance already registered by the required id/name, + * returning the preexistent one instead. + */ + return babl; + } + + babl = model_new (name, id, components, component); + + /* Since there is not an already registered instance by the required + * id/name, inserting newly created class into database. + */ + babl_db_insert (db, babl); + return babl; } diff --git a/babl/babl-type.c b/babl/babl-type.c index 7004dd6..3a182e2 100644 --- a/babl/babl-type.c +++ b/babl/babl-type.c @@ -128,14 +128,22 @@ babl_type_new (void *first_arg, va_end (varg); + babl = babl_db_exist (db, id, first_arg); + if (babl) + { + /* There is an instance already registered by the required id/name, + * returning the preexistent one instead. + */ + return babl; + } + babl = type_new (first_arg, id, bits); - { - Babl *ret = babl_db_insert (db, babl); - if (ret != babl) - babl_free (babl); - return ret; - } + /* Since there is not an already registered instance by the required + * id/name, inserting newly created class into database. + */ + babl_db_insert (db, babl); + return babl; } -- 2.30.2